package com.study.service;

import com.study.dao.BookDao;
import com.study.domain.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SaleService {
    BookDao bookDao;

    @Autowired
    public void setBookDao(BookDao bookDao) {
        this.bookDao = bookDao;
    }

    public void insert(Book book){
        bookDao.insertBook(book);
    }
    @Transactional
    public void onSale(float sale){
        List<Book> bookList=bookDao.queryAll();
        for(Book b:bookList){
            b.setPrice(b.getPrice()*sale);
            bookDao.modifyBook(b);
        }
    }

    public List<Book> queryAll() {
        return bookDao.queryAll();
    }
}
